package com.ymm.system.dao.mapper;

import com.ymm.system.api.constants.CargoEntity;
import com.ymm.system.api.constants.DriverEntity;
import com.ymm.system.api.constants.LltorderEntity;
import com.ymm.system.api.constants.TradeEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

/**
 * 
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2022-08-03
 */
@Mapper
public interface CargoMapper{

    /**
     * 根据ID查询指定货源
     * @param
     * @return
     */
    @Cacheable(value = "cargoDetails", key = "#cargoId")
    CargoEntity getCargoDetailsById(@Param("cargoId") Long cargoId);

    /**
     * 获取指定范围内超过30分钟的货源信息
     * @param
     * @return
     */
    List<CargoEntity> listOutTimeCargoByLocation(@Param("longitude") Double longitude, @Param("latitude") Double latitude, @Param("minute")Integer minute);
    
    List<CargoEntity> listOutTimeCargoByLocation2(@Param("longitude") Double longitude, @Param("latitude") Double latitude, @Param("longitudeDelta") Double longitudeDelta, @Param("latitudeDelta") Double latitudeDelta, @Param("minute")Integer minute);
    
    List<CargoEntity> getAllCargos();

    /**
     * 查找所有已上架超过一天的货源
     * @return
     */
    List<Long> listOutTimeOneDayCargoId();

    /**
     * 获取指定范围内当前时间可装货的货源
     * @param latitude
     * @param longitude
     * @return
     */
    List<CargoEntity> listCargoNowByLocation(@Param("longitude") Double longitude, @Param("latitude") Double latitude);

    /**
     * 存入货源信息cargo
     * @Param: [cargo]
     * @return: void
     */
    void deliverCargoByShipper(CargoEntity cargo);

    /**
     * 根据cargoId查询cargo
     * @Param: [cargoId]
     * @return: Integer
     */
    Integer queryCargoStateById(Long cargoId);

    /**
     * 更改货源状态
     * @Param: [cargoId, cargoState]
     * @return: void
     */
    @CacheEvict(value = {"cargoDetails", "cargo"}, key = "#cargoId")
    Integer updateCargoState(@Param("cargoId") Long cargoId, @Param("cargoState") Integer cargoState);

    /**
     * 将货源状态从from改为to
     * @Param: [cargoId, cargoState]
     * @return: void
     */
    @CacheEvict(value = {"cargoDetails", "cargo"}, key = "#cargoId")
    Integer updateCargoStateFromTo(@Param("cargoId") Long cargoId, @Param("cargoStateFrom") Integer cargoStateFrom, @Param("cargoStateTo") Integer cargoStateTo);

    /**
     * 根据货主id，查询所有货源(brief)
     * @Param: [shipperId]
     * @return: List<CargoEntity>
     */
    List<CargoEntity> queryCargoByShipperIdAndState(@Param("shipperId")Long shipperId, @Param("cargoState") Integer cargoState);

    /**
     * 根据货源id查询货源（详情）
     * @Param: [cargoId]
     * @return: CargoEntity
     */
    @Cacheable(value = "cargo", key = "#cargoId")
    CargoEntity queryCargoByCargoId(Long cargoId);

    List<CargoEntity> listCargoByDeliveryTimeAndLocation(@Param("deliveryTimeEarliest") Date deliveryTimeEarliest, @Param("deliveryTimeLatest")Date deliveryTimeLatest,
                                                        @Param("longitude") Double longitude, @Param("latitude") Double latitude);

    List<CargoEntity> listCargoByDeliveryTimeAndLocation2(@Param("deliveryTimeEarliest") Date deliveryTimeEarliest, @Param("deliveryTimeLatest") Date deliveryTimeLatest, @Param("longitude") Double longitude, @Param("latitude") Double latitude, @Param("longitudeDelta") Double longitudeDelta, @Param("latitudeDelta") Double latitudeDelta);
}